using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;


namespace GameWP
{
    public class PlayPauseComponent : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Game _game;
        private SpriteBatch _spriteBatch;
        private Texture2D _bgPauseMenu;
        private Vector2 touchPosition;
        private Vector2 _parallax;        
        public Vector2 Parallax
        {
            get { return _parallax; }
            set { _parallax = value; }
        }

        private Button _resume;
        public Button Resume
        {
            get { return _resume; }
            set { _resume = value; }
        }

        private Button _quit;
        public Button Quit
        {
            get { return _quit; }
            set { _quit = value; }
        }


        //Initilation
        public PlayPauseComponent(Game game, SpriteBatch spriteBatch, Texture2D bg, SpriteFont textFont)
            : base(game)
        {
            _game = game;
            _spriteBatch = spriteBatch;
            _bgPauseMenu = bg;
            Parallax = Vector2.Zero;

            //Init list menu item
            _resume = new Button("Resume", textFont, new Vector2(300, 200), Color.Red);
            _quit = new Button("Quit", textFont, new Vector2(300, 250), Color.Red);
        }

        public override void Initialize()
        {
            // TODO: Add your initialization code here
                base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here    
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                _game.Exit();
            //Key input
            if (TouchPanel.IsGestureAvailable)
            {
                // Read in the Gesture input
                GestureSample gesture = TouchPanel.ReadGesture();
                // Process Gestures
                if (gesture.GestureType == GestureType.Tap)
                {
                    touchPosition = gesture.Position;
                    _resume.ButtonIsTouched(touchPosition, 0);
                    _quit.ButtonIsTouched(touchPosition, 0);
                }
            }
            
        }

        public override void Draw(GameTime gameTime)
        {
            _spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ManagerGame.camera.GetViewMatrix(Parallax));
                base.Draw(gameTime);
                _spriteBatch.Draw(_bgPauseMenu, new Vector2(235, 150), Color.White);
                _resume.Draw(_spriteBatch, gameTime);
                _quit.Draw(_spriteBatch, gameTime);
            _spriteBatch.End();
        }
    }
}
